﻿using System;
using System.Collections.Generic;
using System.Linq;
//
using PerceptiveMCAPI;
using PerceptiveMCAPI.Types;
//

namespace PerceptiveMCAPI_Test
{
   public partial class get_listMergeVars : System.Web.UI.UserControl
   {

      public ApiMethod method { get; set; }

      public string listId
      {
         get { return tbListId.Text.Trim(); }
         set { tbListId.Text = value; }
      }
      public string tag
      {
         get { return tbMVTag.Text.Trim(); }
         set { tbMVTag.Text = value; }
      }
      public string name
      {
         get { return tbMVName.Text.Trim(); }
         set { tbMVName.Text = value; }
      }

      public mergevar_options options
      {
         get { return get_mergevar_options(); }
      }

      // -----------------------------------------------   
      public void Setup()
      {
         this.Visible = true;
         lblSection.Text = method.section;
         lblMethod.Text = method.name;
         tbListId.Focus();
         //
         divMaintTag.Visible = false;
         divAddTag.Visible = false;
         divUpdateTag.Visible = false;
         //
         switch ( method.name )
         {
            case "listMergeVars":
               break;
            case "listMergeVarAdd":
               divMaintTag.Visible = true;
               divAddTag.Visible = true;
               divUpdateTag.Visible = true;
               break;
            case "listMergeVarUpdate":
               divMaintTag.Visible = true;
               divUpdateTag.Visible = true;
               break;
            case "listMergeVarDel":
               divMaintTag.Visible = true;
               break;
         }
         //
         ddlField_Type.SelectedValue = MCAPISettings.default_listMergeVarAdd_field_type.ToString();
         cbMVReq.Checked = MCAPISettings.default_listMergeVarAdd_req;
         cbMVPublic.Checked = MCAPISettings.default_listMergeVarAdd_public;
         cbMVShow.Checked = MCAPISettings.default_listMergeVarAdd_show;
         tbMVDefault.Text = "";
         tbMVChoices.Text = "";
      }
      // -----------------------------------------------   
      private mergevar_options get_mergevar_options()
      {
         mergevar_options opts = new mergevar_options();
         opts.field_type = ApiHelper.GetEnumFromString<EnumValues.field_Type>( ddlField_Type.SelectedValue );
         opts.req = cbMVReq.Checked;
         opts.@public = cbMVPublic.Checked;
         opts.show = cbMVShow.Checked;
         opts.default_value = tbMVDefault.Text.Trim();
         opts.choices = getChoices();
         // 
         return opts;
      }

      private List<string> getChoices()
      {
         string[] str = tbMVChoices.Text.Split( new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries );
         return str.ToList();
      }
   }
}